﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Text;

namespace Web
{
    public partial class pics : PageBase
    {
        StringBuilder sb = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                int id = PageBase.GetQueryInt("id", 0);
                int currentpage = PageBase.GetQueryInt("page", 1);
                if (id == 0)
                {
                    Response.Redirect("index.aspx");
                }
                else
                {
                    getModel(id,currentpage);
                    loadData(id, currentpage);
                }
            }
            lblmap.Text = ViewState["map"].ToString();
        }
        private void getModel(int id,int currentpage)
        {
            if (currentpage == 1)
            {
                TuKu.BLL.urltable bll = new TuKu.BLL.urltable();
                DataTable dt = bll.GetList(" trim(url) ='" + id.ToString() + "'").Tables[0];
                if (dt.Rows.Count > 0)
                {
                    picshowtitle.Text = dt.Rows[0]["title"].ToString();
                    sb = new StringBuilder();
                    sb.Append("<a href=\"/pics.aspx?id=" + id.ToString() + "&page=2\" title=\"" + dt.Rows[0]["title"] + "_1\">");
                    sb.Append("<img src=\"" + dt.Rows[0]["picPage"].ToString() + "\" ");
                    sb.Append(" alt=\"" + dt.Rows[0]["title"] + "_1\" name=\"slide_pic\" border=\"0\" id=\"slide_pic\" /></a>");
                    litpicshow.Text = sb.ToString();
                    ViewState["map"] = "<a href='index.aspx'>图巨多</a>&gt;<a href='piclist.aspx?id=" + dt.Rows[0]["categoryid"].ToString() + "'>" + map[int.Parse(dt.Rows[0]["categoryid"].ToString())] + "</a>&gt;" + dt.Rows[0]["title"].ToString() + "_1";

                }
                else
                {
                    Response.Redirect("index.aspx");
                }
            }
            else
            {
                TuKu.BLL.urlsubtable bll = new TuKu.BLL.urlsubtable();
                DataTable dt = bll.GetList(" url='"+id.ToString()+"' and currentpage="+currentpage.ToString()).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    picshowtitle.Text = dt.Rows[0]["title"].ToString();
                    sb = new StringBuilder();
                    sb.Append("<a href=\"/pics.aspx?id=" + id.ToString() + "&page=" + (currentpage + 1).ToString() + "\" title=\"" + dt.Rows[0]["title"] + "_" + dt.Rows[0]["currentpage"].ToString() + "\">");
                    sb.Append("<img src=\"" + dt.Rows[0]["picPage"].ToString() + "\" ");
                    sb.Append(" alt=\"" + dt.Rows[0]["title"] + "_1\" name=\"slide_pic\" border=\"0\" id=\"slide_pic\" /></a>");
                    litpicshow.Text = sb.ToString();
                    ViewState["map"] = "<a href='index.aspx'>图巨多</a>&gt;<a href='piclist.aspx?id=" + dt.Rows[0]["categoryid"].ToString() + "'>" + map[int.Parse(dt.Rows[0]["categoryid"].ToString())] + "</a>&gt;" + dt.Rows[0]["title"].ToString() + "_" + dt.Rows[0]["currentpage"].ToString();
                }
                else
                {
                    Response.Redirect("/pics.aspx?id=" + id.ToString() + "&page=1");
                }
            }
        }
        private void loadData(int id, int currentpage)
        {
            TuKu.BLL.urlsubtable bll = new TuKu.BLL.urlsubtable();
            DataTable dt = bll.GetList(" trim(url)='" + id.ToString() + "' order by currentpage ").Tables[0];
            sb = new StringBuilder();
            if (currentpage == 1)
            {
                sb.Append("<a class='on' >1</a>");
                foreach (DataRow dr in dt.Rows)
                {
                    sb.Append("<a href='/pics.aspx?id=" + id.ToString() + "&page=" + dr["currentpage"].ToString() + "'>" + dr["currentpage"].ToString() + "</a>");
                }
                sb.Append("<a href=\"/pics.aspx?id=" + id.ToString() + "&page=" + (currentpage + 1).ToString() + "\" id=\"nextUrl\"><img src=\"/style/img/pageDown.gif\" alt=\"下一页\" /></a>");

            }
            else
            {
                sb.Append("<a href='/pics.aspx?id=" + id.ToString() + "&page=1'>1</a>");
                foreach (DataRow dr in dt.Rows)
                {
                    if (currentpage == int.Parse(dr["currentpage"].ToString()))
                    {
                        sb.Append("<a class='on'>" + currentpage.ToString() + "</a>");
                    }
                    else
                    {
                        sb.Append("<a href='/pics.aspx?id=" + id.ToString() + "&page=" + dr["currentpage"].ToString() + "'>" + dr["currentpage"].ToString() + "</a>");
                    }
                }
                sb.Append("<a href=\"/pics.aspx?id=" + id.ToString() + "&page=" + (currentpage + 1).ToString() + "\" id=\"nextUrl\"><img src=\"/style/img/pageDown.gif\" alt=\"下一页\" /></a>");
              
            }
            this.litpicpage.Text = sb.ToString();
        }
    }
}
